package kr.saeildamil.androidStudy_second.ani;

import kr.saeildamil.androidStudy_second.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class TweenListener extends Activity {
	LinearLayout mlLinear;
	Button mBtn;
	Animation mAni1;
	Animation mAni2;
	Animation mAni3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_tweenlistener);

		mlLinear = (LinearLayout) findViewById(R.id.ch23_tweenlistener_linear);

		mBtn = (Button) findViewById(R.id.tweenlistener_start);
		mBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				mBtn.startAnimation(mAni1);
			}
		});
		mAni1 = AnimationUtils.loadAnimation(this, R.anim.rotate2);
		mAni2 = AnimationUtils.loadAnimation(this, R.anim.alpha2);
		mAni3 = AnimationUtils.loadAnimation(this, R.anim.scale2);

		mAni1.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {
			}

			public void onAnimationRepeat(Animation animation) {
			}

			public void onAnimationEnd(Animation animation) {
				mBtn.startAnimation(mAni2);
			}
		});

		mAni2.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {
			}

			public void onAnimationRepeat(Animation animation) {
			}

			public void onAnimationEnd(Animation animation) {
				mBtn.startAnimation(mAni3);
			}
		});

		mAni3.setAnimationListener(new AnimationListener() {
			public void onAnimationStart(Animation animation) {
			}

			public void onAnimationRepeat(Animation animation) {
			}

			public void onAnimationEnd(Animation animation) {
				Toast.makeText(TweenListener.this, "Animation End",
						Toast.LENGTH_SHORT).show();
			}
		});
	}
}
